package com.elem.util;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.elem.test.DruidTest;

import javax.sql.DataSource;
import java.io.InputStream;
import java.util.Properties;

public class DruidUtil {
    static DataSource dataSource;
    static {
        try {
            Properties pro = new Properties();
            InputStream is = DruidTest.class.getClassLoader().getResourceAsStream("druid.properties");
            pro.load(is);

            // 获取数据库连接池对象
            dataSource = DruidDataSourceFactory.createDataSource(pro);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    // 获取数据库连接池对象
    public static DataSource getDataSource(){
        return dataSource;
    }


    // 获取连接对象 Connection


    // 释放资源
//    public static void close() {
}
